﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using HCFramework.API.LINQ;

namespace C
{
    public class OrderContactController
    {
        public static void Insert(OrderContact a)
        {
            HCDataContext db = new HCDataContext();
            db.OrderContacts.InsertOnSubmit(a);
            db.SubmitChanges();
        }

        public static void Update(OrderContact a, HCDataContext db)
        {
            db.SubmitChanges();
        }

        public static void Delete(int id)
        {
            HCDataContext db = new HCDataContext();
            OrderContact a = db.OrderContacts.Where(
                ik => ik.OrderContactID == id).First();
            db.OrderContacts.DeleteOnSubmit(a);
            db.SubmitChanges();
        }

        public static OrderContact GetByID(int id, HCDataContext db)
        {
            return db.OrderContacts.Where(
                ik => ik.OrderContactID == id).FirstOrDefault();
        }

        public static OrderContact GetByID(int id)
        {
            return GetByID(id, new HCDataContext());
        }

        public static OrderContact GetOrInsert(int orderId)
        {
            HCDataContext db = new HCDataContext();
            OrderContact ret = db.OrderContacts.Where(ik => ik.OrderID == orderId).FirstOrDefault();
            if (ret != null) return ret;

            ret = new OrderContact();
            ret.Address = "";
            ret.Email = "";
            ret.Name = "";
            ret.OrderID = orderId;
            ret.PhoneNumber = "";
            Insert(ret);
            return ret;
        }
    }
}